# title: 异质性随机前沿模型II——Wang-Ho2010
# author: StableGenius
# date: 2020-01-20
# description: 知乎专栏-科研斗牛犬源代码

# clear workspace
rm(list = ls())

# load packages
library(plm)
library(tidyverse)
library(haven)

# set work directory
setwd(dirname(parent.frame(2)$ofile))

# load user-defined script
source("core.R")

# load dataset and trans to panel data
rawdata <- read_dta("demo_panel.dta") %>%
  pdata.frame(index = c("id", "time"))

# specify model
model <- y ~ x1 + x2 | z1

# estimation
huaji <- sfa_wh(formula = model, data = rawdata)
print(summary(huaji))